const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
  const User = sequelize.define('User', {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    username: {
      type: DataTypes.STRING(50),
      allowNull: true,
      unique: true,
      comment: '用户名'
    },
    password: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: '密码'
    },
    nickname: {
      type: DataTypes.STRING(50),
      comment: '昵称'
    },
    phone: {
      type: DataTypes.STRING(15),
      allowNull: true,
      comment: '手机号'
    },
    email: {
      type: DataTypes.STRING(100),
      unique: true,
      comment: '邮箱'
    },
    avatar: {
      type: DataTypes.STRING(255),
      comment: '头像URL'
    },
    role: {
      type: DataTypes.STRING(20),
      defaultValue: 'user',
      comment: '角色: user, admin'
    },
    status: {
      type: DataTypes.TINYINT,
      defaultValue: 1,
      comment: '状态: 0-禁用, 1-正常'
    },
    balance: {
      type: DataTypes.DECIMAL(10, 2),
      defaultValue: 0,
      comment: '账户余额'
    },
    points: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
      comment: '积分'
    },
    level: {
      type: DataTypes.INTEGER,
      defaultValue: 1,
      comment: '会员等级'
    },
    wx_openid: {
      type: DataTypes.STRING(100),
      unique: true,
      comment: '微信OpenID'
    },
    wx_unionid: {
      type: DataTypes.STRING(100),
      unique: true,
      comment: '微信UnionID'
    }
  }, {
    tableName: 'users',
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at'
  });

  return User;
}; 